import {applyMiddleware, createStore, compose} from "redux";
import {persistStore, persistReducer} from "redux-persist";
import storage from "redux-persist/lib/storage";
import thunk from "redux-thunk";
import {createLogger} from "redux-logger";

import reducer from '../reducer';


const persistConfig = {
  key: 'root',
  storage,
  whitelist: ['']
};

const persistedReducer = persistReducer(persistConfig, reducer);

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

const middleWares = [];
middleWares.push(thunk);
const loggerMiddleware = createLogger({
  predicate: () => process.env.NODE_ENV === 'development',
});
middleWares.push(loggerMiddleware);


export const store = createStore(
  persistedReducer,
  composeEnhancers(applyMiddleware(...middleWares))
);

export const persistor = persistStore(store);